<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            margin: 20px auto;
            text-align: center;
        }

        .font {
            width: 200px;
            height: 200px;
            background-color: #000;
            color: #f00;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="box">
        属性名：<input class="bag" type="text" value="background">
        <br>
        <br>
        属性值：<input class="ys" type="text" value="#fff">
        <br>
        <br>
        <section>
            <button type="button" class="yes">确定</button>
            <button type="button" class="no">重置</button>
        </section>
        <br>
        <br>
        <div class="font">在上方输入框输入"属性名"及"属性值"，点击确定按钮查看效果。</div>
    </div>
</body>

<script>
    // 1. 监听
    var change = function (a1, b1, c1) {
        a1.style[b1] = c1
    }

    // 2. 获取节点
    var input = document.getElementsByTagName('input')  // 俩输入框
    // 属性名：
    var ys = document.getElementsByTagName('ys')  // 属性值：
    var font = document.querySelector('.font') // 下面盒子
    var yes = document.querySelector('.yes')  // 确定按钮
    var no = document.querySelector('.no')  // 重置按钮

    // 3.点击确定按钮
    yes.onclick = function () {
        var b = input[0].value
        var c = input[1].value
        change(font, b, c)
    }

    no.onclick = function () {
        font.removeAttribute('style')
    }

</script>

</html>